#include "Server.h"
using namespace yazi::server;

#include "TaskDispatcher.h"
using namespace yazi::thread;

#include "SocketHandler.h"
using namespace yazi::socket;

#include "Singleton.h"
using namespace yazi::utility;



Server::Server() : m_ip(""), m_port(0), m_threads(1024), m_max_conn(1024), m_wait_time(10){

}

Server::~Server(){

}

void Server::listen(const string& ip, const int port){
    m_ip = ip;
    m_port = port;
}

void Server::start(){
    TaskDispatcher* dispatcher = Singleton<TaskDispatcher>::instance();
    dispatcher->init(m_threads);

    SocketHandler* sockethandler = Singleton<SocketHandler>::instance();
    sockethandler->listen(m_ip, m_port);
    sockethandler->handle(m_max_conn, m_wait_time);
}

void Server::set_threads(const int threads){
    m_threads = threads;
}

void Server::set_max_conn(const int max_conn){
    m_max_conn = max_conn;
}

void Server::set_wait_time(const int wait_time){
    m_wait_time = wait_time;
}